package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.client.api.scene.operate.IOperateSceneCommonService;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.LocalInstallDetailAddressAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @Classname LocalInstallDetailAddressAttrLinkHandler
 * @Description
 * @Author cheng.leizhen
 * @Date 2021-03-02 14:53
 */
@Service
@AttrHandler(LocalInstallDetailAddressAttrHandler.class)
public class LocalInstallDetailAddressAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Autowired
    private IOperateSceneCommonService operateSceneCommonService;

    @Resource
    private IQuerySceneInstService querySceneInstService;
    
    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        // 互联网专线 IP地址备案信息模块中 单位详细地址  与装机地址属性联动
        if (Objects.isNull(attr)) {
            return;
        }
        KiteAttr  unitDetailAddressAttr = querySceneInstService.getCommonAttr(data.getSceneInstId(),"2_0000211");
        if (Objects.nonNull(unitDetailAddressAttr) && KiteStringUtils.isNotEmpty(attr.getValueDesc())) {
            unitDetailAddressAttr.setValue(attr.getValueDesc());
            unitDetailAddressAttr.setValueDesc(attr.getValueDesc());
            operateSceneCommonService.setCommonAttr(data.getSceneInstId(), unitDetailAddressAttr);
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
